package com.hwg.emp.web.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.hwg.emp.common.exception.EmpException;
import com.hwg.emp.service.DeptService;
import com.hwg.emp.service.EmployeeService;
import com.hwg.emp.service.ServiceFactroy;
import com.hwg.emp.service.UserService;

public class DeleteEmpsController extends HttpServlet{
      @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    	// TODO Auto-generated method stub
    	  try {
  			String ids = req.getParameter("ids");
  			String sids[]=ids.split(",");
  			EmployeeService e_service = ServiceFactroy.getService(EmployeeService.class);
  			UserService u_service = ServiceFactroy.getService(UserService.class);
  				e_service.deleteEmpsByIds(sids);
  	  			u_service.deleteUsersByIds(sids);
  		} catch (EmpException e) {
  			req.setAttribute("message", e.getMessage());
  			e.printStackTrace();
  		} catch (Exception e) {
  			e.printStackTrace();
  			req.setAttribute("message", "系统繁忙,请稍后再试!");
  		}
  		req.getRequestDispatcher("/selectEmps.do").forward(req, resp);
  	}
  	
    
}
